package main

import "fmt"

/**
寻找最长不含有重复字符的字符串
例: abcdabbd -> abcd = 4
*/
func find(s string) int {
	lastOccurred := make(map[byte]int)
	start := 0
	maxLength := 0
	for i, ch := range []byte(s) {
		// 检测map中是否存在下标
		lastI, ok := lastOccurred[ch]
		// 如果存在将开始位置加1
		if ok && lastI >= start {
			start = lastI + 1
		}

		if i-start+1 > maxLength {
			maxLength = i - start + 1
		}
		lastOccurred[ch] = i
	}

	for i, _ := range lastOccurred {
		fmt.Println(string(i))
	}

	return maxLength
}

func main() {
	fmt.Println(
		find("aabcdabbd"),
		//find("bbbbbbb"),
		//find("ababed"),
	)
}
